<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: mslaria $ ($Date: 2007/07/19 13:41:03 $)
// $RCSfile: upgrade.php,v $ : $Revision: 1.11 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!file_exists(dirname(__FILE__)."/index.php"))
{
	echo "<font face='Verdana, Arial, Helvetica' size='2' color='red'>Please upload the index.php from the setup directory of package to use the upgrade system</font>";
	exit;
}

/**
* Variable declarations, Should be replaced by Build Generator
*/

define("SETUPTYPE", "Upgrade");
define("INTERFACETYPE", "WEB");
// Set default directory becomes swift/
if (defined("SWIFTCUSTOMPATH"))
{
	chdir(SWIFTCUSTOMPATH);
} else {
	chdir('./../');
}

set_magic_quotes_runtime(0);
ini_set('session.use_trans_sid',false);
ini_set('session.bug_compat_42',true);

// Disable NOTICE errors
error_reporting(E_ALL & ~E_NOTICE);

require_once ("./includes/functions.php");
require_once ("./setup/includes/functions.php");

$_SETUP["modules"] = getSetupModules();
require_once ("./config/config.php");
require_once ("./includes/SmartyLight/class.template.php");
require_once ("./locale/". cleanVar($_SWIFT["adminlanguage"]) ."/setup.php");
$dbCore = new dbCore($_DB["hostname"], $_DB["username"], $_DB["password"], $_DB["name"], $_DB["type"], true, $_DB["port"]);
$registry = new Registry;
$datastore = new DataStore;
$cookie = new Cookie;

$_SWIFT["steps"] = array(
0 => "License Agreement",
1 => "Verify Details",
2 => "Auto Upgrade",
3 => "Finish"
);

if (!isset($_POST["step"]))
{
	// someone passed a malformed step or perhaps _POST[step] isnt set? So lets set it to 0
	$_POST["step"] = 0;
}


/*
* We need to authenticate and then start the upgrade process
*/
if ($_POST["step"] == "2")
{
	if (empty($_POST["username"]) || empty($_POST["password"]))
	{
		$_POST["step"] = "1";
		$_SWIFT["errormsg"] = true;
		$_SWIFT["errormsg"] = "Username or Password is Empty";
	} else {
		require_once (dirname(__FILE__)."/steps/upgrade_step2.php");
	}
}

/*
* Display Finish Page
*/
if ($_POST["step"] == "3")
{
	require_once (dirname(__FILE__)."/steps/upgrade_step3.php");
}

/*
* Display Verify Database Page
*/
if ($_POST["step"] == "1")
{
	require_once (dirname(__FILE__)."/steps/upgrade_step1.php");
}

/*
* Display License Agreement Page, Its basically same as setup file so why create seperate file? Use the same one!
*/
if ($_POST["step"] == "0")
{
	require_once (dirname(__FILE__)."/steps/upgrade_step0.php");
}
?>